from GChartWrapper import Line, VerticalBarStack
from random import randint


thumbScale = 4


# Generate a Google chart link for the votes
def genLineChart( scores, isThumb = False ):
  scale = thumbScale if isThumb else 1
  l = str( len( scores ) )

  # Generate the string
  url = "http://chart.apis.google.com/chart"
  url += "?chxr=0,0,10|1,0," + l
  url += "&chxt=y,x"
  url += "&chs=" + str( 500 / scale ) + "x" + str( 350 / scale )
  url += "&cht=lxy"
  url += "&chco=3333FF,FF3311"
  url += "&chds=0," + l + ",0,10,0," + l + ",0,10"
  url += "&chd=t:-1|" + ','.join( [str( int( v.vote ) ) for v in scores] )
  url += "|-1|" + ','.join( [str( v.score )[0:4:1] for v in scores] )
  url += "&chg=0,10,0,0"
  url += "&chma=5,5,5,5"

  return url



# Genearte a google chart link for the histogram
def genHistChart( hist, isThumb = False ):
  scale = thumbScale if isThumb else 1
  maxHist = str( max( hist ) )

  # Generate the source for the chart
  url = "http://chart.apis.google.com/chart"
  url += "?chxr=0,1,10|1,0," + maxHist
  url += "&chxt=x,y"\
         "&chbh=a"\
         "&chs=" + str( 500 / scale ) + "x" + str( 350 / scale ) + \
         "&cht=bvg"\
         "&chco=A2C180"\
         "&chds=0," + maxHist + \
         "&chd=t:"
  url += ','.join( str( h ) for h in hist )

  return url



# Convert the thumb and image URLs into BB code
def linkify( thumb, image ):
  src = "[url=" + image + "]"
  src += "[img]" + thumb + "[/img]"
  src += "[/url]"
  return src




def genCharts( s, h ):
  t = genLineChart( s, True )
  l = genLineChart( s, False )
  V = linkify( t, l )

  t = genHistChart( h, True )
  l = genHistChart( h, False )
  H = linkify( t, l )


  return V, H


if __name__ == "__main__":
  print 'main'
